#ifndef USERDATABASE_H
#define USERDATABASE_H

#include "Database.h"
#include "User.h"

#include <QList>

/*!
 * @addtogroup Database
 * @{
 * @class UserDatabase
 * @brief Manages user account information stored in the database.
 *
 * The UserDatabase class is used to retrieve and store user account
 * information including username, password, and account type
 * (patient, doctor, etc).
 * @}
 */

class UserDatabase : public Database
{
public:
    UserDatabase();
    ~UserDatabase();

    /*! Adds a user with the specified username, password, and type to the
     *  database
     * @param username Unique username of the user to add.
     * @param password Password of the user.
     * @param type Type of user. Types are defined in User::UserType enum.
     * @returns Id of added user if successful. If a user with the specified
     *          username already exists in the database
     *          UserDatabase::USER_EXISTS is returned. If a database error
     *          occured, Database::FAILURE is returned.
     */
    int addUser(QString username, QString password, User::UserType type);

    /*! Gets user id of user with specified username and password.
     * @returns Id of user if found. Database::FAILURE is returned if the user
     *          was not found, or a database error occured.
     */
    int getId(QString username, QString password);

    /*! Gets type (doctor, nurse, etc) of user with specified user id.
     * @param username Username of user.
     * @param password Password of user.
     * @returns User::UserType value of the user type if found. User::INVALID
     *          is returned if the user was not found.
     */
    User::UserType getType(int userId);

    /*! Returns a list of all user ids of users of a single type.
     */
    QList<int> * getUsersOfType(User::UserType type);

    static const int USER_EXISTS = -2;

private:
    void initDatabase();
    QString passwordHash(const QString password, const QString salt) const;
    QString generateSalt() const;

    QList<int> userList;
};

#endif // USERDATABASE_H
